package com.example.springLearning.part15.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
public class FilterConfiguration {

    @Bean
    public FilterRegistrationBean authFilter() {
        FilterRegistrationBean filter = new FilterRegistrationBean<>();
        filter.setName("authFilter");
        filter.setFilter(new AuthFilter());
        filter.setOrder(2);
        filter.setUrlPatterns(Collections.singleton("/spring/*"));
        return filter;
    }

    @Bean
    public FilterRegistrationBean costFilter() {
        FilterRegistrationBean filter = new FilterRegistrationBean<>();
        filter.setName("timeRunFilter");
        filter.setFilter(new TimeRunFilter());
        filter.setOrder(1);
        filter.setUrlPatterns(Collections.singleton("/spring/*"));
        return filter;
    }
}
